﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using YJKArchUtils.Utils;
using YJKRevitDimensionText.OneKeyPlanDim.LevelDim;
using YJKRevitDimensionText.OneKeyPlanDim.Utility;

namespace YJKRevitDimensionText.OneKeyPlanDim.DimData
{
	public class DbDimBase
	{
		public PlanarFace ComponentInSlopePlanarFace
		{
			get
			{
				return this.m_ComponentInSlopePlanarFace;
			}
			set
			{
				this.m_ComponentInSlopePlanarFace = value;
			}
		}

		public bool IsOutArch
		{
			get
			{
				return this.m_bOutArch;
			}
		}

		public bool IsLevelDimed
		{
			get
			{
				return this.m_bLevelDimed;
			}
		}

		public string FloorLevelVal
		{
			get
			{
				return this.m_dFloorLevelVal.ToString("f3");
			}
		}

		public double dFloorLevelVal
		{
			get
			{
				return this.m_dFloorLevelVal;
			}
			set
			{
				this.m_dFloorLevelVal = value;
			}
		}

		protected void SetSlopeOcclusionArea(FamilyInstance slopeDim)
		{
			CurveLoop slopeDimCurveLoop = OcclusionArea.GetSlopeDimCurveLoop(slopeDim);
			OcclusionArea.GetInstance().m_lstSlopeDimCvLoop.Add(slopeDimCurveLoop);
		}

		public bool GetDbAxialWithDir(XYZ xyzDir, out DbAxial dbAxial)
		{
			List<DbAxial> lstDbAxial = KeyComponent.GetInstance().m_lstDbAxial;
			dbAxial = null;
			if (lstDbAxial == null || lstDbAxial.Count == 0)
			{
				return false;
			}
			foreach (DbAxial dbAxial2 in lstDbAxial)
			{
				if (GeometryHelper.VectorParallelVector(dbAxial2.AxialDir, xyzDir))
				{
					dbAxial = dbAxial2;
					return true;
				}
			}
			return false;
		}

		protected bool IsNeedAnalysisInfo()
		{
			if (!this.m_bAnalysis)
			{
				this.m_bAnalysis = true;
				return true;
			}
			return false;
		}

		public virtual bool CreateSizeDim(Autodesk.Revit.DB.Document doc)
		{
			this.m_doc = doc;
			return (this.m_bOutArch && OneKeyPlanDimSelctionDim.m_bOutArchSize) || (!this.m_bOutArch && OneKeyPlanDimSelctionDim.m_bInArchSize);
		}

		public virtual bool CreateLevelDim(Autodesk.Revit.DB.Document doc, out List<SingleLevelDimDataInfo> lstSingleLevelDimDataInfo)
		{
			lstSingleLevelDimDataInfo = new List<SingleLevelDimDataInfo>();
			this.m_doc = doc;
			if ((this.m_bOutArch && OneKeyPlanDimSelctionDim.m_bOutArchLevel) || (!this.m_bOutArch && OneKeyPlanDimSelctionDim.m_bInArchLevel))
			{
				return true;
			}
			if (!this.m_bLevelDimed)
			{
				this.m_bLevelDimed = true;
			}
			return false;
		}

		public virtual bool CreateSlopeDim(Autodesk.Revit.DB.Document doc)
		{
			this.m_doc = doc;
			return (this.m_bOutArch && OneKeyPlanDimSelctionDim.m_bOutArchSlope) || (!this.m_bOutArch && OneKeyPlanDimSelctionDim.m_bInArchSlope);
		}

		public void SetWallInOrOut(XYZ pt, List<Curve> lstCv)
		{
			this.m_bOutArch = true;
			if (GeometryHelper.IsInCvLoop(pt, lstCv))
			{
				this.m_bOutArch = false;
			}
		}

		public void SetWallInOrOut(XYZ pt, List<CurveLoop> lstCvLoop)
		{
			this.m_bOutArch = true;
			foreach (CurveLoop curveLoop in lstCvLoop)
			{
				List<XYZ> list = new List<XYZ>();
				foreach (Curve curve in curveLoop)
				{
					list.AddRange(curve.Tessellate());
				}
				if (Geometry.PointInPloygon(list, pt, 0.0001, 0.0001) == 1)
				{
					this.m_bOutArch = false;
					break;
				}
			}
		}

		protected Document m_doc;

		protected bool m_bOutArch = true;

		protected bool m_bAnalysis;

		protected bool m_bLevelDimed;

		private string m_strFloorLevelVal = string.Empty;

		private double m_dFloorLevelVal;

		private PlanarFace m_ComponentInSlopePlanarFace;
	}
}
